/**
 *  Copyright 2002-2009 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package foo.bar.blog.web.action;

import java.util.EnumSet;
import java.util.Set;

/**
 * Represents the day of a month.
 *
 * @author tmjee
 * @version $Date: 2009-03-14 06:53:07 +0000 (Sat, 14 Mar 2009) $ $Id$
 */
public enum DayEnum {

    DAY1(){public int day() { return 1; }},
    DAY2(){public int day() { return 2; }},
    DAY3(){public int day() { return 3; }},
    DAY4(){public int day() { return 4; }},
    DAY5(){public int day() { return 5; }},
    DAY6(){public int day() { return 6; }},
    DAY7(){public int day() { return 7; }},
    DAY8(){public int day() { return 8; }},
    DAY9(){public int day() { return 9; }},
    DAY10(){public int day() { return 10; }},
    DAY11(){public int day() { return 11; }},
    DAY12(){public int day() { return 12; }},
    DAY13(){public int day() { return 13; }},
    DAY14(){public int day() { return 14; }},
    DAY15(){public int day() { return 15; }},
    DAY16(){public int day() { return 16; }},
    DAY17(){public int day() { return 17; }},
    DAY18(){public int day() { return 18; }},
    DAY19(){public int day() { return 19; }},
    DAY20(){public int day() { return 20; }},
    DAY21(){public int day() { return 21; }},
    DAY22(){public int day() { return 22; }},
    DAY23(){public int day() { return 23; }},
    DAY24(){public int day() { return 24; }},
    DAY25(){public int day() { return 25; }},
    DAY26(){public int day() { return 26; }},
    DAY27(){public int day() { return 27; }},
    DAY28(){public int day() { return 28; }},
    DAY29(){public int day() { return 29; }},
    DAY30(){public int day() { return 30; }},
    DAY31(){public int day() { return 31; }};

    public abstract int day();

    public static DayEnum convert(int _day) {
        Set<DayEnum> days = EnumSet.allOf(DayEnum.class);
        for (DayEnum day: days) {
            if (day.day() == _day)  {
                return day;
            }
        }
        return null;
    }

    public static DayEnum convert(String _day) {
        Set<DayEnum> days = EnumSet.allOf(DayEnum.class);
        for (DayEnum day: days) {
            if (day.name().equals(_day)) {
                return day;
            }
        }
        return null;
    }
}
